from datetime import datetime
from typing import List, Union, Literal

from sqlmodel import SQLModel, Field
from sqlalchemy import Column, Text

from app.models.base import PageParams, EmptyStrToNone


class SystemLogLogin(SQLModel, table=True):
    __tablename__ = "system_log_login"

    id: int = Field(default=None, primary_key=True, index=True, nullable=False, description="注解")
    admin_id: int = Field(default=0, nullable=False, description="管理员ID")
    username: str = Field(default='', max_length=30, nullable=False, description="登录账号")
    ip: str = Field(default='', max_length=30, nullable=False, description="登录地址")
    os: str = Field(default='', max_length=100, nullable=False, description="操作系统")
    browser: str = Field(default='', max_length=100, nullable=True, description="浏览器")
    status: int = Field(default=1, nullable=False, description="操作状态: 1=成功, 2=失败")
    create_time: int = Field(default=0, nullable=False, description="创建时间")


class SystemLogLoginListIn(PageParams):
    name: Union[str, None] = Field(default=None)
    code: Union[str, None] = Field(default=None)
    isStop: Union[int, None, EmptyStrToNone] = Field(default=None)


class SystemLogLoginListOut(SQLModel):
    data: list[SystemLogLogin]
    count: int
